import request from '@/utils/request'
// import store from '@/store/index' // 获取vuex

// 封装注册的接口
export const registerAPI = ({ username, password, repassword }) => {
  return request({
    method: 'POST',
    url: '/api/reg',
    data: {
      username,
      password,
      repassword
    }
  })
}

// 封装登录的接口
export const loginAPI = ({ username, password }) => {
  return request({
    method: 'POST',
    url: '/api/login',
    data: {
      username,
      password
    }
  })
}

// 封装获取用户基本资料的接口  需要带上token
export const getUserInfoAPI = () => {
  return request({
    method: 'GET',
    url: '/my/userinfo'
    // headers: { // 把vuex存储的token传入
    //   Authorization: store.state.token
    // }
  })
}

// 获取侧边栏数据的接口
export const getMenusListAPI = () => {
  return request({
    method: 'GET',
    url: '/my/menus'
    // headers: { // 把vuex存储的token传入
    //   Authorization: store.state.token
    // }
  })
}

// 获取更新用户资料的接口
// eslint-disable-next-line camelcase
export const updtUserInfoAPI = ({ id, username, nickname, email, user_pic }) => {
  return request({
    method: 'PUT',
    url: '/my/userinfo',
    data: {
      id,
      username,
      nickname,
      email,
      user_pic
    }

  })
}

// 更新用户头像的接口
export const updatUserAvaterAPI = (avatar) => {
  return request({
    method: 'PATCH',
    url: '/my/update/avatar',
    data: {
      avatar
    }
  })
}

// 更新用户密码的接口
// eslint-disable-next-line camelcase
export const updatePwdAPI = ({ old_pwd, new_pwd, re_pwd }) => {
  return request({
    method: 'PATCH',
    url: '/my/updatepwd',
    data: {
      old_pwd, // 旧密码
      new_pwd, // 新密码
      re_pwd // 新密码-确认
    }
  })
}

// 获取文章分类的接口
export const getArtCateListAPI = () => {
  return request({
    method: 'GET',
    url: '/my/cate/list'
  })
}

// 增加文章分类的接口
// eslint-disable-next-line camelcase
export const addArtCateAPI = ({ cate_name, cate_alias }) => {
  return request({
    method: 'POST',
    url: '/my/cate/add',
    data: {
      cate_name, // 文章分类名字
      cate_alias // 文章分类别名
    }
  })
}

// 修改文章的接口
// eslint-disable-next-line camelcase
export const updateArtCateAPT = ({ id, cate_name, cate_alias }) => {
  return request({
    method: 'PUT',
    url: '/my/cate/info',
    data: {
      id, // 文章分类id
      cate_name, // 文章分类名字
      cate_alias // 文章分类别名

    }
  })
}

// 删除文章的接口
export const delArtCateAPI = (id) => {
  return request({
    method: 'DELETE',
    url: '/my/cate/del',
    params: {
      id
    }
  })
}
